﻿using EventAggregationModule;
using EventAggregationModule.Models;
using Microsoft.Practices.Prism.PubSubEvents;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Product_2
{
    public class IProduct_2presenter
    {
        private string _lotnumber;

        private IEventAggregator eventAggregator;
        private SubscriptionToken subscriptionToken;

        public IProduct_2presenter(IEventAggregator eventAggregator)
        {
            this.eventAggregator = eventAggregator;
            LotNumberEvent lotnumberEvent = eventAggregator.GetEvent<LotNumberEvent>();


            if (subscriptionToken != null)
            {
                lotnumberEvent.Unsubscribe(subscriptionToken);
            }

            subscriptionToken = lotnumberEvent.Subscribe(LotNumberEventHandler, ThreadOption.UIThread, false);
        }

        public void LotNumberEventHandler(LotNumber lotNumber)
        {

            Debug.Assert(View != null);
            View.SetAdd(number.Su1, number.Su2);
            View.SetSub(number.Su1, number.Su2);
            View.SetMul(number.Su1, number.Su2);
            View.SetDiv(number.Su1, number.Su2);
        }


        public IProduct_2View View { get; set; }

        public string LotNumber
        {
            get
            {
                return _lotnumber;
            }
            set
            {
                _lotnumber = value;
            }
        }
    }
}
